package sa.huang;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;

import javax.xml.namespace.QName;

public class Data {

	public ArrayList<String> getMessageLinksList() {
		return messageLinksList;
	}

	/**
	 * add ml to ML.
	 * 		*  used by algo 3.1 
	 * @param ml
	 */
	public void setMessageLinksList(String ml) {
		messageLinksList.add(ml);
	}
	public ArrayList<QName> getMessageConstructsList() {
		return messageConstructsList;
	}
	
	/**
	 * add mc to MC.  
	 * 		*  used by algo 3.1
	 * @param String mc
	 */
	public void setMessageConstructsList(QName mc) {
		messageConstructsList.add(mc);
	}
	public HashMap<String, String> getPaType_PaMap() {
		return paType_PaMap;
	}
	
	/**
	 * put (pa, paType) pair into paType_PaMap.
	 * 		*  used by algo 3.1
	 * @param pa
	 * @param paType
	 */
	public void setPaType_PaMap(String pa, String paType) {
		paType_PaMap.put(pa, paType);
	}
	public HashMap<String, QName> getProcess_PaTypeMap() {
		return process_PaTypeMap;
	}
	
	/**
	 * put (paType, process) pair into process_PaTypeMap.
	 * 		*  used by algo 3.1
	 * @param paType
	 * @param process
	 */
	public void setProcess_PaTypeMap(String paType, QName process) {
		process_PaTypeMap.put(paType, process);
	}
	public HashMap<QName, String> getNsprefix_ProcessMap() {
		return nsprefix_ProcessMap;
	}
	
	/**
	 * put (process, nsprefix) pair into nsprefix_ProcessMap.
	 * 		*  used by algo 3.1
	 * @param process
	 * @param nsprefix
	 */
	public void setNsprefix_ProcessMap(QName process, String nsprefix) {
		nsprefix_ProcessMap.put(process, nsprefix);
	}
	public HashMap<String, ArrayList<QName>> getConstructs_MLMap() {
		return constructs_MLMap;
	}
	
	/**
	 * put (ml,(mc1,mc2)) pair into counstructs_MLMap.
	 * 		*  used by algo 3.1
	 * @param ml
	 * @param mc1
	 * @param mc2
	 */
	public void setConstructs_MLMap(String ml, QName mc1, QName mc2) {
		ArrayList<QName> constructsPair = new ArrayList<QName>();
		constructsPair.add(0, mc1);
		constructsPair.add(1, mc2);
		constructs_MLMap.put(ml, constructsPair);
	}
	public HashMap<String, ArrayList<Object>> getParefs_MLMap() {
		return parefs_MLMap;
	}
	
	/**
	 * put (ml, (senders, receiver)), that is (ml, (A,b)) pair into parefs_MLMap.
	 * 		*  used by algo 3.2, initiated in algo 3.1
	 * @param ml
	 * @param senders
	 * @param receiver
	 * 
	 * ArrayList<String> A here is a data structure used by Comm, A contains a set of pas as senders,
	 * or a pa as sender, this name A is not self-describing, one possible name might be senderOrSenders.
	 *  
	 */
	public void setParefs_MLMap(String ml, ArrayList<String> senders, String receiver) {
		ArrayList<Object> parefsPair = new ArrayList<Object>();
		ArrayList<String> A = new ArrayList<String>();
		A = senders;
		parefsPair.add(0, A);
		parefsPair.add(1, receiver);
		parefs_MLMap.put(ml, parefsPair);
	}
	
	/**
	 * put (ml,(sender, receiver)) i.e. (ml, (A,b)) pair into parefs_MLMap.
	 * 		*  used by algo 3.2, initiated in algo 3.1
	 * @param ml
	 * @param sender
	 * @param receiver
	 */
	public void setParefs_MLMap(String ml, String sender, String receiver){
		ArrayList<Object> parefsPair = new ArrayList<Object>();
		ArrayList<String> A = new ArrayList<String>();
		A.add(sender);
		parefsPair.add(0, A);
		parefsPair.add(1, receiver);
		parefs_MLMap.put(ml, parefsPair);
	}
	
	public HashMap<String, QName> getScope_PaMap() {
		return scope_PaMap;
	}

	/**
	 * put(pa, scope) pair or (pa, foreach) pair into scope_PaMap
	 * 		* initiated in algo 3.1
	 * @param pa
	 * @param scope
	 */
	public void setScope_PaMap(String pa, QName scope) {
		scope_PaMap.put(pa, scope);
	}

	
	public HashMap<String, String> getBindSenderTo_MLMap() {
		return bindSenderTo_MLMap;
	}
	
	/**
	 * put (ml, actualSender) pair into bindSenderTo_MLMap.
	 * 		*  used by algo 3.1
	 * @param ml
	 * @param actualSender
	 */
	public void setBindSenderTo_MLMap(String ml, String actualSender) {
		bindSenderTo_MLMap.put(ml, actualSender);
	}
	
	public void setNsprefix_PTMap(QName pt) {
		nsprefix_PTMap.put(pt, pt.getPrefix());
		
	}
	
	public void setPortType_MCMap(QName mc, QName pt) {
		portType_MCMap.put(mc, pt);
	}
	public QName portType_MC(String wsuID){
		QName pt = new QName("localpart");
		Iterator<QName> iter = portType_MCMap.keySet().iterator();
		while(iter.hasNext()){
			QName key = iter.next();
			if(key.getLocalPart().equals(wsuID)){
				QName value = portType_MCMap.get(key);
				pt = value;
			}
		}
		return pt;
	}
	
	public void setOperation_MCMap(QName mc, QName o) {
		operation_MCMap.put(mc, o);
	}
	public String operation_MCID(String wsuID){
		String op = new String();
		Iterator<QName> iter = operation_MCMap.keySet().iterator();
		while(iter.hasNext()){
			QName key = iter.next();
			if(key.getLocalPart().equals(wsuID)){
				QName value = operation_MCMap.get(key);
				op = value.getLocalPart();
			}
		}
		return op;
	}
	
	public HashSet<Comm> getCommSet() {
		return commSet;
	}

	public void setCommSet(Comm comm) {
		commSet.add(comm);
	}
	public void setTNS(String ns){
		tns = ns;
	}
	public String getTNS(){
		return tns;
	}
	

	
	public void setCorrPropNameSet(String propName){
		corrPropNameSet.add(propName);
	}
	
	public void setPropertySet(QName property){
		propertySet.add(property);
	}
	
	public void setProperty_CorrPropNameMap(String propName, QName property){
		property_CorrPropNameMap.put(propName, property);
	}
	public HashMap<String, QName> getProperty_CorrPropNameMap(){
		return property_CorrPropNameMap;
	}
	public QName property_CorrPropName(String propName){
		return property_CorrPropNameMap.get(propName);
	}
	
	public void setNsprefix_PropertyMap(QName property, String prefix){
		nsprefix_PropertyMap.put(property, prefix);
	}
	public String nsprefix_Property(QName property){
		return nsprefix_PropertyMap.get(property);
	}


	public void setPortTypeSet(QName pt) {
		portTypeSet.add(pt);		
	}
	
	public HashSet<QName> getPortTypeSet(){
		return portTypeSet;
	}

	public void setParticipantSet(String pa) {
		participantSet.add(pa);
	}
	
	public HashSet<String> getParticipantSet(){
		return participantSet;
	}

	public void setPartnerLinkSet(String pl) {
		partnerLinkSet.add(pl);
	}

	public void setPartnerLinkTypeSet(String plt) {
		partnerLinkTypeSet.add(plt);
	}
	public HashSet<String> getPartnerLinkTypeSet(){
		return partnerLinkTypeSet;
	}

	public void setPartnerLink_MCMap(QName mc, String pl) {
		partnerLink_MCMap.put(mc, pl);
	}
	
	public HashMap<QName, String> getPartnerLink_MCMap() {
		return partnerLink_MCMap;
	}
	public String partnerLink_MCID(String wsuID){
		String pl = new String();
		Iterator<QName> iter = partnerLink_MCMap.keySet().iterator();
		while(iter.hasNext()){
			QName key = iter.next();
			if(key.getLocalPart().equals(wsuID)){
				String value = partnerLink_MCMap.get(key);
				pl = value;
			}
		}
		return pl;
	}

	/**
	 * put (sc, pl) pair into partnerLinks_scopeMap
	 * if partnerLinks_scopeMap already contains the key sc, then add pl into the HashSet, which is stored by the key sc
	 * else, create a new HashSet, add pl in it, and store this HashSet by the key sc
	 * @param sc
	 * @param pl
	 */
	public void setPartnerLinks_scopeMap(QName sc, String pl) {		
		if(partnerLinks_scopeMap.containsKey(sc)){
			partnerLinks_scopeMap.get(sc).add(pl);
		} else {
			HashSet<String> s = new HashSet<String>();
			s.add(pl);
			partnerLinks_scopeMap.put(sc, s);
		}
	}
	public HashMap<QName, HashSet<String>> getPartnerLinks_scopeMap(){
		return partnerLinks_scopeMap;
	}

	public void setPLType_PLMap(String pl, String plt) {
		plType_PLMap.put(pl, plt);
	}

	public String plType_pl(String pl){
		String plt = new String();
		Iterator<String> iter = plType_PLMap.keySet().iterator();
		while(iter.hasNext()){
			String key = iter.next();
			if(key.equals(pl)){
				plt = plType_PLMap.get(key);
			}
		}
		return plt;
	}

	public void setPartnerLinks_CommMap(Comm comm, String pl1, String pl2) {
		ArrayList<String> plPair = new ArrayList<String>();
		plPair.add(0,pl1);
		plPair.add(1,pl2);
		partnerLinks_CommMap.put(comm, plPair);
	}
	
	public  HashMap<Comm, ArrayList<String>> getPartnerLinks_CommMap() {
		return partnerLinks_CommMap;
	}
	

	public void setPlt_CommMap(Comm comm, String plt) {
		plt_CommMap.put(comm, plt);
	}
	public Comm comm_plt(String plt){
		Comm comm = new Comm();
		Iterator<Comm> iter = plt_CommMap.keySet().iterator();
		while(iter.hasNext()){
			Comm key = iter.next();
			String value = plt_CommMap.get(key);
			if(value.equals(plt)){
				comm = key;
			}
		}
		return comm;
	}

	public void setMyRole_PLMap(String pl, String mRole) {
		myRole_PLMap.put(pl, mRole);
	}
	public String myRole_pl(String pl){
		String myRole = new String();
		Iterator<String> iter = myRole_PLMap.keySet().iterator();
		while(iter.hasNext()){
			String key = iter.next();
			if(key.equals(pl)){
				myRole = myRole_PLMap.get(key);
			}
		}
		return myRole;
	}

	public void setPartnerRole_PLMap(String pl, String pRole) {
		partnerRole_PLMap.put(pl, pRole);
	}
	public HashMap<String, String> getPartnerRole_PLMap(){
		return partnerRole_PLMap;
	}
	public String partnerRole_pl(String pl){
		String partnerRole = new String();
		Iterator<String> iter = partnerRole_PLMap.keySet().iterator();
		while(iter.hasNext()){
			String key = iter.next();
			if(key.equals(pl)){
				partnerRole = partnerRole_PLMap.get(key);
			}
		}
		return partnerRole;
	}

	/**
	 * scopeSet contains List<QName> (TParticipantSet.getForEach())and QName (TParticipantSet.getScope())
	 * @param forEach
	 */
	public void setScopeSet(Object sc) {
		scopeSet_ForSetMethod.add(sc);
	}

	/**
	 * 
	 * only works for the situation that each paSet contains only one forEach now 
	 * @return all the sc (forEach or scope)in scopeSet
	 */
	@SuppressWarnings("unchecked")
	public HashSet<QName> getScopeSet() {
		for(Object o:scopeSet_ForSetMethod){
			if(o instanceof QName){
				scopeSet_ForGetMethod.add((QName) o);
			} else {
				for(QName q: (List<QName>)o){
					scopeSet_ForGetMethod.add(q);
				}
			}
		}
		
		return scopeSet_ForGetMethod;
	}
	
	
	
	private String tns = new String();
	
	private HashMap<String, String> paType_PaMap = new HashMap<String, String>();
	private HashMap<String, QName> process_PaTypeMap = new HashMap<String, QName>();
	private HashMap<QName, String> nsprefix_ProcessMap = new HashMap<QName, String>();
	private HashMap<String, ArrayList<QName>> constructs_MLMap = new HashMap<String, ArrayList<QName>>();
	private HashMap<String, ArrayList<Object>> parefs_MLMap = new HashMap<String, ArrayList<Object>>();
	private HashMap<String, String> bindSenderTo_MLMap = new HashMap<String, String>();
	private HashMap<String, QName> scope_PaMap = new HashMap<String, QName>();
	private HashMap<QName, String> nsprefix_PTMap = new HashMap<QName, String>();
	private HashMap<QName, QName> portType_MCMap = new HashMap<QName, QName>();
	private HashMap<QName, QName> operation_MCMap = new HashMap<QName, QName>();
	private HashMap<QName, String> partnerLink_MCMap = new HashMap<QName, String>();
	private HashMap<QName, HashSet<String>> partnerLinks_scopeMap = new HashMap<QName, HashSet<String>>();
	private HashMap<String, String> plType_PLMap = new HashMap<String, String>();
	private HashMap<Comm, ArrayList<String>> partnerLinks_CommMap = new HashMap<Comm, ArrayList<String>>();
	private HashMap<Comm, String> plt_CommMap = new HashMap<Comm, String>();
	private HashMap<String, String> myRole_PLMap = new HashMap<String, String>();
	private HashMap<String, String> partnerRole_PLMap = new HashMap<String, String>();
	private HashMap<String, QName> property_CorrPropNameMap = new HashMap<String, QName>();
	private HashMap<QName, String> nsprefix_PropertyMap = new HashMap<QName, String>();
	
	private HashSet<String> participantSet = new HashSet<String>();
	private HashSet<QName> portTypeSet = new HashSet<QName>();
	private HashSet<Comm> commSet = new HashSet<Comm>();
	private HashSet<String> partnerLinkSet = new HashSet<String>();
	private HashSet<String> partnerLinkTypeSet = new HashSet<String>();
	private HashSet<Object> scopeSet_ForSetMethod = new HashSet<Object>();
	private HashSet<QName> scopeSet_ForGetMethod = new HashSet<QName>();
	private HashSet<String> corrPropNameSet = new HashSet<String>();
	private HashSet<QName> propertySet = new HashSet<QName>();
	private ArrayList<String> messageLinksList = new ArrayList<String>();
	private ArrayList<QName> messageConstructsList = new ArrayList<QName>();


}
